<template>
    <div>
       <h1>显示康复理疗信息</h1>
    </div>
      项目名称:
      <input type="text" v-model="ye.name">

       <input type="button" value="查询" @click="seletee">
       <input type="button" value="批量修改状态" @click="pangupdate">
     <table class="table">
        <thead>
            <tr>
                 <td>
                    <input type="checkbox" @change="selete" v-model="yu">
                 </td>
                <td>项目名称</td>
                <td>时长</td>
                <td>服务数量</td>
                <td>康复名称</td>
                <td>佣金</td>
                <td>项目说明</td>
                <td>是否删除</td>
                <td>操作</td>
            </tr>
        </thead>
         <tbody>
            <tr v-for="a in data">
                <td>
                    <input type="checkbox" v-model="idayy"  :value="a.rehabilitationId">
                </td>
                <td>{{a.rehabilitationName}}</td>
                <td>{{a.duration}}</td>
                <td>{{a.num}}</td>
                <td>{{a.roteName}}</td>
                <td>{{a.price}}</td>
                <td>{{a.rehabiType}}</td>
                <td :style="a.isdeletable?'color:green':'color:red'">{{a.isdeletable?"未删除":"删除"}}</td>
             
                 <td>{{a.iState==true?"启用":"禁用"}}</td>

                <td>
         <input type="button" value="逻辑删除" @click="updaye(a.rehabilitationId)">

                </td>
            </tr>
        </tbody>
     </table>

   一共{{ye.count}}条,每页显示{{ye.size}}条,共{{ye.mumber}}页,当前{{ye.index}}页

    <input type="button" value="首页" @click="pange(1)">
    <input type="button" value="上一页" @click="pange(2)">

  <input type="button" :value="d" v-for="d in ye.mumber" @click="ytye(d)">

    <input type="button" value="下一页" @click="pange(3)">
    <input type="button" value="尾页" @click="pange(4)">

 <input type="mumberr" style="width:45px;height:45px" v-model="ye.index"><input type="button" value="跳转" @click="et">
     <select v-model="ye.size" @change="pau">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>

     </select>
</template>

<script setup lang="ts">
 import axios from 'axios';
  import{ref,onMounted} from 'vue';
 import {useRouter} from 'vue-router';
   const router=useRouter();

    onMounted(()=>{

            ShowRehabilitation();

        rotes();
    

    })



//全选/全取消

 const yu=ref(false);


   const selete=()=>{

    if(yu.value){
        
         idayy.value=[];

          data.value.forEach(h=>{
              idayy.value.push(h.rehabilitationId)
          })
  
    }else{

   idayy.value=[];//清空

    }
    

   }

   
 const idayy=ref([]);






 const updaye=(ids:number)=>{

     if(confirm("确认要删除吗")){

      axios.get("https://localhost:7235/api/Rehabilitation/UpdateState",{params:{id:ids}}).then(res=>{
          if(res.data>0){
  alert("逻辑删除成功")
   ShowRehabilitation();
          }else{
  alert("逻辑删除失败")
 

          }

      })
     }

 }
     const pangupdate=()=>{

         if(confirm("确认要批量修改状态吗")){
       axios.delete("https://localhost:7235/api/Rehabilitation/UpdateRageAnync",{params:{idsting:idayy.value.toString()}}).then(res=>{
              if(res.data>0){
            alert("批量修改状态成功")
               ShowRehabilitation();
              }else{
             alert("批量修改状态成功")
              }
        })
         }
 
     }
    
  const op=ref([{
    "roteId": 0,
    "roteName": ""
  }])

     const rotes=()=>{
         axios.get("https://localhost:7235/api/Rote/rotes").then(res=>{
              op.value=res.data;

         })
     }

//跳转
      const et=()=>{

   if(ye.value.index<1||ye.value.index>ye.value.mumber){
     ye.value.index=1;
   }else{
        ShowRehabilitation();

   }

      }

 const ytye=(val:any)=>{
     ye.value.index=val;
        ShowRehabilitation();

 }

  const pau=()=>{
     ye.value.index=1;
ShowRehabilitation();


  }


 const data=ref([{
       
      "roteId": 2,
      "rehabilitationId": 8,
      "rehabilitationName": "酒店项目",
      "code": "20250612211",
      "duration": 15,
      "num": 6,
      "price": 5000,
      "rehabiType": "再接再厉",
      "roteName": "社会康复",
      "isdeletable": 0
    
 }])

 const seletee=()=>{
  ye.value.index=1;

ShowRehabilitation();

 }




  const pange=(val:any)=>{

        if(val==1){

   ye.value.index=1
   
   ShowRehabilitation();

        }

    if(val==2&&ye.value.index>1){

   ye.value.index--;

   ShowRehabilitation();

        }

      if(val==3&&ye.value.index<ye.value.mumber){

   ye.value.index++;
   ShowRehabilitation();

        }

    if(val==4){

     ye.value.index=ye.value.count

   ShowRehabilitation();

        }


  }

 const ye=ref({
     name:'',
     index:1,
     size:2,
     count:0,
     mumber:0,

 })

  const ShowRehabilitation=()=>{
    axios.get("https://localhost:7235/api/Rehabilitation/ShowRehabilitation",{params:ye.value}).then(res=>{
          data.value=res.data.mumber
        ye.value.count=res.data.count
         ye.value.mumber=Math.ceil(ye.value.count/ye.value.size);

    })
  }

</script>

<style scoped>

</style>
